
# generate table F5

# load packages
library(rio) # load data
library(tidyverse) # data manipulation
library(stargazer) # generate tables
library(sensemakr) # sensitivity analysis

# set working directory
setwd("~/replication_files/")

# load data for analysis
data_with_dictionary <- import("data/full_data.csv") %>%
  mutate(across(c(imf_program,field_discovery,grad_school_econ_usa,iso3c,year), as.factor)) %>% # treat factors as factors
  # rename variables so they look nicer in the figures
  rename(`IMF Program` = imf_program,
         `Field Discovery` = field_discovery_lag)


ols1 <- lm(policy_passage ~ resource_mentions_absolute_lag + 
             previous_policy +  grad_school_econ_usa + fdi_performance_index_lag +
             `IMF Program` + price_crudeoil_lag + price_crudeoil_difference + 
             resource_rents_lag + log_gdp_per_capita_lag + gdp_growth_lag + `Field Discovery` + 
             polyarchy + left_executive + protest + year + iso3c, data = data_with_dictionary)

# benchmark: IMF program
content.sensitivity1 <- sensemakr(model = ols1, 
                                  treatment = "resource_mentions_absolute_lag",
                                  benchmark_covariates = "`IMF Program`1",
                                  kd = 3) # investigate the max strength of a confounder 1x, 2x, 3x as strong as the benchmark

# benchmark: field discovery
content.sensitivity2 <- sensemakr(model = ols1, 
                                  treatment = "resource_mentions_absolute_lag",
                                  benchmark_covariates = "`Field Discovery`",
                                  kd = 3) # investigate the max strength of a confounder 1x, 2x, 3x as strong as the benchmark


# table F5 is a combination of both tables below
ovb_minimal_reporting(content.sensitivity1)
ovb_minimal_reporting(content.sensitivity2)
